/*
https://leetcode.cn/problems/longest-substring-without-repeating-characters/submissions/562215712/
LC03. 无重复字符的最长子串
*/

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        int len=0;
        int n=s.size();
        unordered_map<char , int>mp;
        int l=0,r=0;
        for(int i=0;i<n;++i){
            ++mp[s[i]];
            while(mp[s[i]]>1){
                --mp[s[l]];
                ++l;
            }
            len=max(len,r-l+1);
            ++r;
        }
        return len;
    }
};